_run_cmd: override user aliases in run()#1359
Merged
Merged
Conversation
If a user aliased "hg log" to "hg log --graph" [^1] (apparently this is widespread, see [^2]), mercurial based setups do not work, because "hg log" output needs to be reset to a canonical form. This is done setting the environment variable HGRCPATH= to an empty value. A previous attempt at normalizing hg output was done on 2010-08-29, when e0954e3 ("inline getoutput, set HGPLAIN to disable hg i18n"), introduced HGPLAIN=1, but this change is not sufficient for protecting against `hg log` aliasing. An example of command that is fixed with this change is the compilation of mercurial itself in local mode (here shown for 7.2.1): ``` $ make local ... File "<HOME>/.cache/uv/builds-v0/.tmpcFxMQB/lib64/python3.14/site-packages/vcs_versioning/_run_cmd.py", line 173, in run res.check_returncode() ~~~~~~~~~~~~~~~~~~~~^^ File "/usr/lib64/python3.14/subprocess.py", line 508, in check_returncode raise CalledProcessError(self.returncode, self.args, self.stdout, self.stderr) subprocess.CalledProcessError: Command '['hg', 'log', '-r', '.', '-T', '{node}\n{tag}\n{date|shortdate}']' returned non-zero exit status 255. ``` [^1]: `hg log` can be aliased editing the contents of `hgrc`: ``` [alias] log = log --graph ``` [^2]: https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/604c086ddde6f40309c03ae7e5050c7c8d87e75a
Contributor
Author
|
Hi, can this PR be considered for review? |
RonnyPfannschmidt
approved these changes
Apr 25, 2026
Contributor
|
rtd error unrelated, thanks |
Contributor
Author
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a user aliased
hg logtohg log --graph1 (apparently this is widespread, see 2), mercurial based setups do not work, becausehg logoutput needs to be reset to a canonical form.This is done setting the environment variable
HGRCPATH=to an empty value.A previous attempt at normalizing hg output was done on 2010-08-29, when e0954e3 ("inline getoutput, set HGPLAIN to disable hg i18n"), introduced
HGPLAIN=1, but this change is not sufficient for protecting againsthg logaliasing.An example of command that is fixed with this change is the compilation of mercurial itself in local mode (here shown for 7.2.1):
Footnotes
↩hg logcan be aliased editing the contents ofhgrc:https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/604c086ddde6f40309c03ae7e5050c7c8d87e75a ↩